package com.android.equipment.dao.operate;

import com.android.equipment.ObjectBox;
import com.android.equipment.dao.DeviceModel;
import com.android.equipment.dao.DeviceModel_;
import com.android.equipment.dao.People;
import com.android.equipment.dao.People_;

import java.util.List;

import io.objectbox.Box;
import io.objectbox.query.Query;
import io.objectbox.query.QueryBuilder;

public class DaoDeviceModel {
    static Box<DeviceModel> peopleBox;
    private static DaoDeviceModel instance;

    private DaoDeviceModel() {
    }

    public static DaoDeviceModel getInstance() {
        if (instance == null) {
            instance = new DaoDeviceModel();
            peopleBox = ObjectBox.get().boxFor(DeviceModel.class);
        }
        return instance;
    }

    public long addDeviceModel(DeviceModel deviceModel) {
        return peopleBox.put(deviceModel);
    }

    public void deleteDeviceModel(DeviceModel deviceModel) {
        peopleBox.remove(deviceModel);
    }

    public void updateDeviceModel(DeviceModel deviceModel) {
        peopleBox.put(deviceModel);
    }

    public DeviceModel getDeviceModel(long id) {
        return peopleBox.get(id);
    }

    public DeviceModel getDeviceModel(String modelCode){
        Query<DeviceModel> query = peopleBox.query(DeviceModel_.modelCode.equal(modelCode)).build();
        DeviceModel deviceModel = query.findFirst();
        query.close();
        return deviceModel;
    }
    public List<DeviceModel> getNotDelDeviceModel() {
        Query<DeviceModel> query = peopleBox.query(DeviceModel_.isDel.equal(false)).build();
        List<DeviceModel> deviceModelList = query.find();
        query.close();
        return deviceModelList;
    }


}
